// Only use a custom transport if a proxy is configured, right now libgit2
// doesn't support proxies and we have to use a custom transport in this
// case. The custom transport, however, is not as well battle-tested.
- match cargo::ops::http_proxy(config) {
- Ok(Some(..)) => {}
+ match cargo::ops::http_proxy_exists(config) {
+ Ok(true) => {}
_ => return
}
pub use self::cargo_test::{run_tests, run_benches, TestOptions};
pub use self::cargo_package::package;
pub use self::registry::{publish, registry_configuration, RegistryConfig};
-pub use self::registry::{registry_login, search, http_proxy, http_handle};
+pub use self::registry::{registry_login, search, http_proxy_exists, http_handle};
pub use self::registry::{modify_owners, yank, OwnersOptions};
pub use self::cargo_fetch::{fetch};
pub use self::cargo_pkgid::pkgid;
Ok(handle)
}
-/// Find a globally configured HTTP proxy if one is available.
+/// Find an explicit HTTP proxy if one is available.
///
-/// Favor cargo's `http.proxy`, then git's `http.proxy`, then finally a
-/// HTTP_PROXY env var.
-pub fn http_proxy(config: &Config) -> CargoResult<Option<String>> {
+/// Favor cargo's `http.proxy`, then git's `http.proxy`. Proxies specified
+/// via environment variables are picked up by libcurl.
+fn http_proxy(config: &Config) -> CargoResult<Option<String>> {
match try!(config.get_string("http.proxy")) {
Some((s, _)) => return Ok(Some(s)),
None => {}
}
Err(..) => {}
}
- Ok(env::var("HTTP_PROXY").ok())
+ Ok(None)
+}
+
+/// Determine if an http proxy exists.
+///
+/// Checks the following for existence, in order:
+///
+/// * cargo's `http.proxy`
+/// * git's `http.proxy`
+/// * http_proxy env var
+/// * HTTP_PROXY env var
+/// * https_proxy env var
+/// * HTTPS_PROXY env var
+pub fn http_proxy_exists(config: &Config) -> CargoResult<bool> {
+ if try!(http_proxy(config)).is_some() {
+ Ok(true)
+ } else {
+ Ok(["http_proxy", "HTTP_PROXY",
+ "https_proxy", "HTTPS_PROXY"].iter().any(|v| env::var(v).is_ok()))
+ }
}
pub fn http_timeout(config: &Config) -> CargoResult<Option<i64>> {